package com.sc.nft.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.*;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.MerchantPledgeTaskConf;
import com.sc.nft.entity.vo.*;
import com.sc.nft.entity.vo.merchantPledgeTask.AdminExaminePageVO;
import com.sc.nft.entity.vo.merchantPledgeTask.AminMerchantPledgeTaskConfDetailsVO;
import com.sc.nft.service.AdminMerchantPledgeTaskConfService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/merchant/pledge/task")
@Api(tags = "商户质押关联")
public class MerchantPledgeTaskController {

    private final AdminMerchantPledgeTaskConfService adminMerchantPledgeTaskConfService;



    @PostMapping(value = "/getExaminePage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取商户质押列表", notes = "获取审核列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminExaminePageVO> getExaminePage(@Valid @RequestBody ExaminePageRequest request) {
        return PageResult.success(adminMerchantPledgeTaskConfService.getExaminePage(request.getDaoName(), request.getExamineStatus(), request.getPageNo(), request.getPageSize()));
    }

    @PostMapping(value = "/getAllDao", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取所有dao接口", notes = "获取所有dao接口", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<AdminUserCreatorInfoAllDao>> getAllDao() {
        return Result.success(adminMerchantPledgeTaskConfService.getAllDao());
    }


    @PostMapping(value = "/getMerchantPledgeTaskConfDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取质押详情", notes = "获取审核列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<AminMerchantPledgeTaskConfDetailsVO> getMerchantPledgeTaskConfDetails(@Valid @RequestBody IdRequest request) {
        return Result.success(adminMerchantPledgeTaskConfService.getMerchantPledgeTaskConfDetails(request.getId()));
    }

    @PostMapping(value = "/examineMerchantPledgeTask", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "审核质押任务", notes = "审核质押任务", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result examineMerchantPledgeTask(@Valid @RequestBody ExamineMerchantPledgeTaskRequest request) {
        adminMerchantPledgeTaskConfService.examineMerchantPledgeTask(request.getId(),request.getExamineStatus(),request.getReason());
        return Result.success();
    }

    @ApiOperation(value = "修改质押活动", notes = "修改质押活动", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updatePledgeTaskInfo", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result updatePledgeTaskInfo(@RequestBody UpdatePledgeTaskRequest request) {
        adminMerchantPledgeTaskConfService.updatePledgeTaskInfo(BeanUtil.copyProperties(request, MerchantPledgeTaskConf.class));
        return Result.success();
    }


    @ApiOperation(value = "商户质押记录", notes = "商户质押记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getMerchantUserPledgeTaskRecordPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<MerchantUserPledgeTaskPageVO> getMerchantUserPledgeTaskRecordPage(@RequestBody MerchantUserPledgeTaskRecordPageRequest request) {
        return PageResult.success(adminMerchantPledgeTaskConfService.getMerchantUserPledgeTaskRecordPage(request.getDaoName(),request.getUserTel(),request.getPledgeName(),request.getStatus(),request.getPageNo(),request.getPageSize(),request.getIsFrozen()));
    }

    @ApiOperation(value = "商户质押记录详情", notes = "商户质押记录详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getMerchantUserPledgeTaskRecordDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<UserMerchantPledgeTaskRecordDetailsVO> getMerchantUserPledgeTaskRecordDetails(@RequestBody IdRequest request) {
        return Result.success(adminMerchantPledgeTaskConfService.getMerchantUserPledgeTaskRecordDetails(request.getId()));
    }


    @ApiOperation(value = "挖宝记录奖励列表", notes = "挖宝记录奖励列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getMerchantUserPledgeTaskRwardsDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<UserPledgeTaskRwardsDetailsVO> getMerchantUserPledgeTaskRwardsDetails(@RequestBody UserPledgeTaskRwardsDetailsRequest request) {
        return PageResult.success(adminMerchantPledgeTaskConfService.getMerchantUserPledgeTaskRwardsDetails(request.getId(),request.getStartTime(),request.getEndTime(),request.getPageNo(),request.getPageSize()));
    }

    @ApiOperation(value = "质押数据导出预览", notes = "质押数据导出预览", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
        @PostMapping(value = "/merchantPledgeDataExportPreview", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<List<MerchantPledgeDataExportPreviewVO>> merchantPledgeDataExportPreview(@RequestBody MerchantPledgeDataExportPreviewRequest request) {
        return Result.success(adminMerchantPledgeTaskConfService.merchantPledgeDataExportPreview(request.getPledgeName(),request.getDaoId()));
    }
}
